package test.thread;

public class Customer implements Runnable {
	
	private ProductStack stack;
	
	public Customer(ProductStack stack){
		this.stack = stack;
	}

	@Override
	public void run() {
		String goods;
		for(int i=0;i<200;i++) {
				System.out.println("point:"+stack.getPoint());
				if(stack.getPoint()>=0) {
					goods = stack.pop();
					Thread.yield();
					System.out.println("customer "+(i+1)+ " get:"+goods);
				} else {
					i = i--;
					if(i==-1) {
						i = 0;
					}
				}
		}
	}

	/**
	 * @return the stack
	 */
	public ProductStack getStack() {
		return stack;
	}

	/**
	 * @param stack the stack to set
	 */
	public void setStack(ProductStack stack) {
		this.stack = stack;
	}
}
